/**
 * @method VuePlugin
 * @description vue的插件
 * @description 该插件提供 v-stat 指令式绑定节点上报
 */
export default class VuePlugin {
	constructor(Vue, options = {}) {
		this.Vue = Vue
		this.options = options
	}

	apply = stat => {
		console.log('Stat use: VuePlugin')

		// 绑定
		const addNode = ( 
			el, 
			{ 
				value = {}
				// value: { 
				// 	id = '', 
				// 	unView = false, 
				// 	unClick = false, 
				// 	...params,
				// } = {},
			} = {},
		) => stat.addNode(el, value)

		// 移除绑定
		const removeNode = ( 
			el, 
			{ 
				value = {}
			} = {}, 
		) => stat.removeNode(value.id)
		
		this.Vue.directive('stat', {
			inserted: addNode,
			componentUpdated: addNode,
			unbind: removeNode,
		})
	}
}